package com.aiwu.utils

import android.widget.ImageView
import coil.load
import coil.request.CachePolicy
import com.aiwu.library.interfaces.ImageLoader

/**
 * Coil的图片加载器
 */
class CoilImageLoader : ImageLoader {
    override fun loadImageIntoImageView(uri: Any, imageView: ImageView) {
        if (uri is String) {
            val isNetUrl = uri.startsWith("http")
            if (!isNetUrl) {
                //本地图片
                imageView.load(uri) {
                    allowHardware(false)
                    memoryCachePolicy(CachePolicy.READ_ONLY)
                    diskCachePolicy(CachePolicy.READ_ONLY)
                }
                return
            }
        }
        imageView.load(uri) {
            allowHardware(false)
            addHeader("Referer", "http://www.25game.com/")
        }
    }
}